package com.bjtu.literatureclient.controller.user;

import com.bjtu.literatureclient.service.user.UserIndexService;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/userIndexNo")
public class UserIndexNoController {
	@Autowired
	private UserIndexService userIndexService;
	
	@RequestMapping(method = RequestMethod.POST, value = "generateUserIndexNo")
	public String generateUserIndexNo(HttpServletRequest request){
		int language=Integer.parseInt(request.getParameter("language"));
		String firstName=request.getParameter("firstName");
		String lastName=request.getParameter("lastName");
		String year=request.getParameter("year");
		String startCode=request.getParameter("startCode");
		String index=userIndexService.createIndexNo(language, firstName,
	             lastName, year,  startCode);
		Gson gson = new Gson();
		return gson.toJson(index);
	}
}
